{% extends "detail.html" %}
{% load static i18n dcrm_tags %}

{% block extra_css %}
{{ block.super }}
{% endblock %}

{% block content %}
<div class="row">
  <div class="col-md-12">
    <div class="box box-primary">
      <div class="box-header with-border">
        <h3 class="box-title">{{ object.title }}</h3>
        <div class="box-tools pull-right">
          <div class="btn-group">
            {% if 'dcrm.change_document' in perms %}
            <a href="{{ object.get_update_url }}" class="btn btn-sm btn-default">
              <i class="fa fa-pencil"></i><span class="hidden-xs"> {% trans "编辑" %}</span>
            </a>
            {% endif %}
            {% if 'dcrm.delete_document' in perms %}
            <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">
              <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu">
              <li>
                <a href="{{ object.get_delete_url }}" class="text-danger">
                  <i class="fa fa-trash"></i> {% trans "删除" %}
                </a>
              </li>
            </ul>
            {% endif %}
          </div>
        </div>
      </div>

      <div class="box-body">
        {% if object.tags.all %}
        <div class="margin-bottom">
          {% for tag in object.tags.all %}
          <span class="label label-info">{{ tag.name }}</span>
          {% endfor %}
        </div>
        {% endif %}

        <div class="margin-bottom" id="doc-content">
          {{ object.content|safe }}
        </div>

        {% if object.attachments.exists %}
        <div class="box box-default collapsed-box">
          <div class="box-header with-border">
            <h3 class="box-title"><i class="fa fa-paperclip"></i> 附件</h3>
            <div class="box-tools pull-right">
              <button type="button" class="btn btn-box-tool" data-widget="collapse">
                <i class="fa fa-plus"></i>
              </button>
            </div>
          </div>
          <div class="box-body">
            <div class="table-responsive">
              <table class="table table-hover">
                <tbody>
                  {% for attachment in object.attachments.all %}
                  <tr>
                    <td style="width: 40px">
                      <i class="fa fa-file-{{ attachment.file_type }}-o"></i>
                    </td>
                    <td>{{ attachment.name }}</td>
                    <td>{{ attachment.file.size|filesizeformat }}</td>
                    <td>{{ attachment.created_at|date:"Y-m-d H:i" }}</td>
                    <td>
                      <a href="{{ attachment.file.url }}" class="btn btn-xs btn-default" download>
                        <i class="fa fa-download"></i> 下载
                      </a>
                    </td>
                  </tr>
                  {% endfor %}
                </tbody>
              </table>
            </div>
          </div>
        </div>
        {% endif %}
      </div>

      <div class="box-footer">
        <div class="description-block pull-left">
          <i class="fa fa-user"></i> {{ object.created_by }} &nbsp;&nbsp;
          <i class="fa fa-clock-o"></i> {{ object.created_at|date:"Y-m-d H:i" }} &nbsp;&nbsp;
          <i class="fa fa-folder"></i> {{ object.categories.first|default:"未分类" }} &nbsp;&nbsp;
          <i class="fa fa-eye"></i> {{ object.views|default:"0" }} 次浏览
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}

{% block extra_js %}
{{ block.super }}
<script>
  $(function () {
    $('#doc-content img').addClass('img-responsive');
  });
</script>
{% endblock %}